import 'package:get/get.dart';
import 'package:kkhousekeep/models/order_list_entity.dart';
import 'package:kkhousekeep/net/home_order_connect.dart';

import '../repair/repair_home_controller.dart';

class OrderInHandListController extends GetxController {
  late HomeOrderConnect _connect;
  final bool isSelf;
  var enableRepairId = 0;
  var enableUrgentId = 0;

  var isShowDialog = false.obs;
  var repairId = 0.obs;
  var urgentId = 0.obs;
  var orderList = <OrderListObj>[].obs;

  OrderInHandListController({
    required this.isSelf,
  });

  @override
  void onInit() {

    _connect = Get.find<HomeOrderConnect>();
    _loadNetworkData();
    super.onInit();
  }

  void performClickTab(TabModel model, bool isRepair) {
    if (isRepair) {
      ///维修区域点击
      repairId.value = model.id;
      return;
    }
    urgentId.value = model.id;
  }

  void _loadNetworkData() async {
    await loadList();
  }

  void filterList(int repairId,int urgentId){
    this.repairId.value = repairId;
    this.urgentId.value = urgentId;
    loadList();
  }
  Future<void> loadList() async {
    OrderListEntity orderListEntity = await _connect.getOrderList(
      type: isSelf ? 'self' : 'transferred',
      state: 'pending',
      repairArea: repairId.value.toString(),
      urgency: urgentId.value.toString(),
    );
    orderList.value = orderListEntity.obj;
  }
}
